package thinkinjava4.ch21_concurrency;

public class Chopstick {
    private boolean taken = false;

    /**
     * 拿起筷子
     */
    public synchronized void take() throws InterruptedException {
        //筷子如果被使用，wait
        while (taken) wait();
        taken = true;
    }

    /**
     * 放下筷子
     */
    public synchronized void drop() {
        taken = false;
        notifyAll();
    }
}
